home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000015_icon-group-sender _Tue Jul 20 14:39:42 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 20 Jul 1993 19:43:14 MST
  2. Date: Tue, 20 Jul 93 14:39:42 PDT
  3. From: alex@laguna.Metaphor.COM (Bob Alexander)
  4. Message-Id: <9307202139.AA17977@laguna.Metaphor.COM>
  5. To: icon-group@cs.arizona.edu
  6. Subject: Re: Mystery about "every"
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10. >From: Ken Walker <kwalker@shara.premenos.sf.ca.us>
  11. >> Paul_Abrahams@MTS.cc.Wayne.edu writes 
  12. >>  
  13. >> ...
  14. >> This program produced the output 83, as expected.  But I then replaced
  15. >> the "every" statement by the following one, which I thought to be more
  16. >> elegant:
  17. >>  
  18. >>    every retval :=  8 * retval + ord(!s) - ord("0")
  19. >>  
  20. >> Now the output of the program is 3 (the last digit), not 83.
  21. >
  22. >Backtracking only goes as far as the generator !s. The expression
  23. >
  24. >   8 * retval
  25. >
  26. >is not reeveluated. The original value of 0 is used in every
  27. >iteration.
  28.  
  29. Try rephrasing it as:
  30.  
  31.     every retval :=  ord(!s) - ord("0") + 8 * retval
  32.  
  33. It works.
  34.  
  35. You can run into some rather non-intuitive stuff using this "short
  36. form" of every -- you have to think hard about the order of evaluation
  37. and exactly which parts of the expression will be re-evaluated.
  38.  
  39. Its safer, and probably more transparent, to use the longer form with
  40. the auxiliary variable -- but not as cute.
  41.  
  42. -- Bob Alexander
  43.  
  44. Metaphor Computer Systems     (415) 966-0751      alex@metaphor.com
  45. ====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex
  46.